Remove spaces in phone numbers in Contacts

Hi,


How do I remove/reformat phone numbers in the Contacts app in OS X El Capitan?


Phone numbers have spaces eg +61 111 222 333 and when using Copy + Paste get rejected by my VOIP application.


Thanks!

iMac, OS X El Capitan (10.11.2)

Posted on Sep 16, 2016 9:24 PM

Reply
5 replies

Sep 17, 2016 5:57 PM in response to Barney-15E

I found a way to make a plugin that will strip non-numeric characters from the phone number.

Copy the following and paste it into a new Script Editor document.

using terms from application "Contacts"

on action property

return "phone"

end action property


on action title for selectedPerson with thisPhoneNumber

return "Copy Digits"

end action title


on should enable action for selectedPerson with thisPhoneNumber

return true

end should enable action


on perform action for selectedPerson with thisPhoneNumber

set phoneToCopy to (value of thisPhoneNumber) as string

set the clipboard to returnNumbers(phoneToCopy)

end perform action


end using terms from



on returnNumbers(phoneNumber)

set theDigits to {"+", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}

set onlyNumbers to ""

repeat with i from 1 to length of phoneNumber

set j to (character i of phoneNumber)

if j is in theDigits then set onlyNumbers to onlyNumbers & j

end repeat

return onlyNumbers

end returnNumbers

Save the script into your user Library/Application Scripts/com.apple.AddressBook folder.

To get to the user Library, hold down the Option key and select Library from the Go menu in Finder.


When you click on the phone number label in Contacts, Copy Digits will appear in the list.


If your VOIP software is scriptable, it might be possible to just have it dial from that menu.


I wrote it to allow + symbols in the string. Does your VOIP software understand the + or does it need to be stripped out?

Sep 17, 2016 5:41 PM in response to dm4n

I can't find a way to alter the copying of the number format in Contacts. The numbers are formatted to match the country code generally recognized formatting. Even if you enter the numbers without formatting, the display will be formatted and anything you copy will too.


Contacts has a Plugin architecture. Perhaps the VOIP software has a plugin for Contacts that allows you to dial from the label menu in Contacts. Or, perhaps there is a plugin out there that will copy the number without the formatting (though, I didn't find one when googling).


You could contact the VOIP software developers and ask them to fix their app because it should be stripping all non-numeric data from the string. It has no idea where you would copy a number from (like a website), and it should be able to parse out the number.

Sep 17, 2016 5:57 PM in response to Barney-15E

Perfect!


It took me a while to recognise that the phone number 'label' eg mobile/home/work is a clickable field.


Copy Digits shows up as an option and does the job.


I use an online service to send SMS occasionally - and it was rejecting phone numbers formatted by OS X Contacts app.


Re: the preceding '+' - my VOIP app (LinPhone) accepts it no problem.


Thanks so much for your plugin. Kudos!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Remove spaces in phone numbers in Contacts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.